<template>
    <div @click="handleClick" v-show="show" class="to-top-container">
        <Icon type="top" />
    </div>
</template>

<script>
import Icon from '@/components/Icon';
export default {
    components: {
        Icon
    },
    data() {
        return {
            show: false,
        }
    },
    created() {
        // 监听主区域的滚动
        this.$bus.$on("mainScroll", this.handleScroll);
    },
    methods: {
        handleScroll(dom) {
            if (!dom) {
                this.show = false;
                return;
            }
            this.show = dom.scrollTop >= 500;
        },
        handleClick() {
            this.$bus.$emit("setMainScroll", 0)
        }
    },
    destroyed() {
        this.$bus.$off('mainScroll', this.handleScroll);
    }
}
</script>

<style lang="less" scoped>
@import url(~@/styles/var.less);

.to-top-container {
    background: @primary;
    border-radius: 50%;
    height: 50px;
    width: 50px;
    position: fixed;
    right: 50px;
    bottom: 50px;
    z-index: 999;
    text-align: center;
    line-height: 50px;
    cursor: pointer;
    font-size: 1.5em;
    color: @f;
}
</style>